package com.fsds.crem.web.timetask;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jxls.transformer.XLSTransformer;


public class Test {

	public static void main(String[] args) {
		
		try {
			
			new Test().test5();
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
	}
	
	public void test5() throws Exception {
		
		String str = "201618";
		
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.MONDAY);
		c.set(Calendar.YEAR, Integer.valueOf(str.substring(0, 4)));
		c.set(Calendar.WEEK_OF_YEAR, Integer.valueOf(str.substring(4)));
		c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); 
		
		Date begin = c.getTime();
		
		c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		
		Date end = c.getTime();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		System.out.println(sdf.format(begin));
		System.out.println(sdf.format(end));
	}
	
	public void test4() throws Exception {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		
		Date begin = sdf.parse("20150430");
		Date end = sdf.parse("20160430");
		
		Calendar c = Calendar.getInstance();
		c.setTime(begin);
		
		List<String> list = new ArrayList<String>();
		
		Calendar ce = Calendar.getInstance();
		ce.setTime(end);
		ce.set(Calendar.DAY_OF_MONTH,1);
		
		while(c.getTime().before(ce.getTime())){
			
			list.add(c.get(Calendar.YEAR) + "" + (c.get(Calendar.MONTH)+1));
			System.out.println(c.get(Calendar.YEAR) + "" + (c.get(Calendar.MONTH)+1));
			
			c.add(Calendar.MONTH, 1);
		}	
	}
	
	public void test3() throws Exception{
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		Calendar c = Calendar.getInstance();
		c.setTime(sdf.parse("20151201"));
		System.out.println(c.get(Calendar.DAY_OF_MONTH));
		
	}
	
	public void test2() throws Exception{
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		
		Date begin = sdf.parse("20150428");
		Date end = sdf.parse("20160428");
		
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.MONDAY);
		c.setTime(begin);
		
		int currentDayOfWeek = c.get(Calendar.DAY_OF_WEEK);
		
		c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		
		if(currentDayOfWeek != Calendar.MONDAY){
			c.add(Calendar.WEEK_OF_YEAR, 1);
		}
		
		List<String> list = new ArrayList<String>();
		
		while(c.getTime().before(end)){
			
			list.add(c.get(Calendar.YEAR) + "" + c.get(Calendar.WEEK_OF_YEAR));
			
			System.out.println(c.get(Calendar.YEAR) + "" + c.get(Calendar.WEEK_OF_YEAR));
			
			c.add(Calendar.WEEK_OF_YEAR, 1);
		}	
		
		Calendar c1 = Calendar.getInstance();
		c1.setTime(begin);	
		System.out.println(c1.get(Calendar.WEEK_OF_YEAR));
		
		Calendar c2 = Calendar.getInstance();
		c2.setTime(end);
		System.out.println(c2.get(Calendar.WEEK_OF_YEAR));
	}
	
	public void test1() throws Exception{
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a", 123132);
		map.put("b", "BBBBBBBBBBBB");
		map.put("c", "你好");
		map.put("d", 456);
		map.put("e", "11111111111111");
		map.put("f", "fdafdasfd");
		
		
		String templatePath = "D:/template.xls";
		String filePath = "D:/test.xls";
		
		XLSTransformer transformer = new XLSTransformer();
		
		String[] names = {"sheet1","sheet2"};
		
		transformer.setSpreadsheetsToRemove(names);
		transformer.transformXLS(templatePath, map, filePath);
		
	}
	
}
